package com.czk.model.ptotorype.practice.serializable;

import java.io.*;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/10/21 11:35
 */
public class SerializableUtil {
    public static void serializePerson() throws IOException {
        Person person = new Person("czk", 27);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("D://person.txt")));
        // 序列化
        objectOutputStream.writeObject(person);
        //
        objectOutputStream.close();
    }

    public static Person deserializePerson() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(new File("D://person.txt")));
        Person person = (Person) objectInputStream.readObject();
        return person;
    }
}
